<template>
  <div class="link_list_box">
    <div class="item_box" v-for="item in props.baseList" :key="item.id" @click="chooseLink(item)">
      <div class="font_box">
        <div class="title">
          <span>{{ item.title }}</span>
          <img v-if="item.type == 7" class="icon_img" src="/static/material/link.png" alt="" />
        </div>
        <div class="link_desc">{{ item.desc }}</div>
      </div>
      <el-image :src="item.cover_image_url" fit="cover" class="image" :class="{icon_radar:item.is_radar==1}"></el-image>
      <div class="choose_box">
        <img v-if="item.isCheck" src="@/assets/image/friendcirclemat/image_choose.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref, reactive, watch } from 'vue'
  import { ElMessage } from 'element-plus'
  // const props = defineProps(['baseList', 'remainNum', 'selectBaseList'])

  interface PropsType {
    baseList?: any[],
    selectBaseList?: any[],
    remainNum?: (string | number),
    multiple?: boolean,
    totalNum: number
  }
  const props = withDefaults(defineProps<PropsType>(), {
    baseList: ()=>[],
    selectBaseList: ()=>[],
    remainNum: 0,
    multiple: true,
    totalNum: 9
  })

  const emit = defineEmits(['getData'])
  const chooseLink = (item: any) => {
    let indx = props.selectBaseList.findIndex((it: any) => it.id === item.id)

    if(props.multiple){
      if (indx === -1) {
        if (props.remainNum <= 0) {
          // ElMessage.warning(`最多可选${props.selectBaseList.length == 0 ? 9 : props.selectBaseList.length }个素材`)
          ElMessage.error(`最多可选${props.totalNum}个素材`);
          return
        }
        item.isCheck = true
        props.selectBaseList.push(item)
      } else {
        props.selectBaseList.splice(indx, 1)
        item.isCheck = false
      }
    }else{
      if (indx === -1) {
        props.baseList.forEach(ite=>{
          ite.isCheck = false
        })
        item.isCheck = true
        props.selectBaseList.splice(0)
        props.selectBaseList.push(item)
      } else {
        item.isCheck = false
        props.selectBaseList.splice(0)
      }
    }
    emit('getData', {
      type: 6,
      typeStr: 'link',
      data: props.selectBaseList
    })
  }

</script>

<style lang="scss" scoped>
  .link_list_box {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .item_box {
      cursor: pointer;
      position: relative;
      box-sizing: border-box;
      width: 290px;
      border-radius: 1px;
      border: 1px solid #eaeaea;
      background: #f9f9f9;
      padding: 5px 6px 5px 28px;
      margin-bottom: 14px;
      display: flex;
      justify-content: flex-start;
      align-items: flex-start;
      .choose_box {
        position: absolute;
        width: 16px;
        height: 16px;
        top: 10px;
        left: 6px;
        background: white;
        border: 1px solid #eaeaea;
        img {
          width: 100%;
          height: 100%;
          position: absolute;
        }
      }
      .font_box {
        box-sizing: border-box;
        background: #f9f9f9;
        width: 180px;
        margin-right: 6px;
        .title {
          display: flex;
          align-items: center;
          width: 180px;
          font-size: 14px;
          font-family: STHeitiSC-Medium, STHeitiSC;
          font-weight: 800;
          color: #33302d;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          word-break: break-all;
          margin-bottom: 6px;
          .icon_img  {
            margin-left: 2px;
            width: 16px;
            height: 16px;
          }
        }
        .link_desc {
          white-space: normal;
          font-size: 12px;
          font-family: STHeitiSC-Light, STHeitiSC;
          font-weight: 300;
          color: #969696;
          line-height: 14px;
          text-overflow: -o-ellipsis-lastline;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
      .image {
        width: 60px;
        height: 60px;
        border-radius: 2px;
      }
      .icon_radar{
        position: relative;
        &::after{
          content: '';
          width: 15px;
          height: 15px;
          background: url('@/assets/image/material/radar_red.png') no-repeat center;
          background-size: cover;
          position: absolute;
          top: 3px;
          right:3px;
        }
      }
     
    }
    
  }
</style>
